package com.moarea.app.util;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

public class JsonUtil {
    public static void writeJson(HttpServletRequest request, HttpServletResponse response, Object data) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String rs = mapper.writeValueAsString(data);
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print(rs);
        out.flush();
        out.close();
    }
}
